package GUI;

import GUITOOl.MyLineBorder;
import Utils.GetWindowsSize;

import java.awt.*;

import javax.swing.JLabel;
import javax.swing.WindowConstants;

/**
 * The type Show message frame.
 *
 * @author dzr
 * @version 1.0
 */
public class showMessageFrame extends javax.swing.JFrame {
    private JLabel text;
    private String str;
    private int x;
    private int y;
    private int width = 200;
    private int height = 50;

    /**
     * Instantiates a new Show message frame.
     *
     * @param str the str
     */
    public showMessageFrame(String str){
        this.str=str;
        this.x = GetWindowsSize.getWindowsSize().width / 2 - width / 2;
        this.y = GetWindowsSize.getWindowsSize().height / 2 - height / 2;
        new Thread(new Runnable() {
            @Override
            public void run() {
                initGUI();
            }
        }).start();
    }

    /**
     * Init the GUI of MessageFrame
     */
    private void initGUI() {
        MyLineBorder myLineBorder = new MyLineBorder(new Color(192, 192, 192), 1 , true);
        Color back=new Color(229, 228, 182);
        try {
            setUndecorated(true);
            setLocationRelativeTo(null);
            setVisible(true);
            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            getContentPane().setBackground(back);
            {
                text = new JLabel("<html>" + str + "</html>", JLabel.CENTER);
                text.setBorder(myLineBorder);
                text.setFont(new Font("微软雅黑",1,18));
                getContentPane().add(text, BorderLayout.CENTER);
            }
            setBounds( x, y, width, height);
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
            dispose();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}